﻿#include "bloodpressuredialog.h"
#include "ui_bloodpressuredialog.h"
#include"userdata.h"
BloodPressureDialog::BloodPressureDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::BloodPressureDialog)
{
    UserData user;
    ui->setupUi(this);
    this->setWindowTitle(QStringLiteral("血压仪"));
    this->setWindowFlag(Qt::FramelessWindowHint);
    user.setName(QStringLiteral("张怡然"));
    user.setAge(25);
    ui->namelabel->setText(QStringLiteral("姓名：")+user.getName());
    ui->agelabel->setText(QString(QStringLiteral("年龄：%1")).arg(user.getAge()));
    m_bloodPressure=new BloodPressure(ui->myplot,ui->HBPData,ui->LBPData,ui->PulseData);
    m_bloodPressure->setParam(1,60);
    m_bloodPressure->buildPlot();
    initBP();
}

BloodPressureDialog::~BloodPressureDialog()
{
    delete ui;
}

void BloodPressureDialog::initBP()
{
    int length=60;
    QVector<unsigned char>HBPHistory;
    HBPHistory.reserve(length);
    QVector<unsigned char>LBPHistory;
    LBPHistory.reserve(length);
    QVector<unsigned char>PulseHistory;
    PulseHistory.reserve(length);
    unsigned char value=0;
    for(int i=0;i<length;i++)
    {
        //随机数测试
        value=120+rand()%10;
        HBPHistory.append(value);
        value=80+rand()%5;
        LBPHistory.append(value);
        value=65+rand()%5;
        PulseHistory.append(value);
    }
    m_bloodPressure->drawHistoryData(QDateTime::currentMSecsSinceEpoch(),HBPHistory,LBPHistory,PulseHistory);
    m_bloodPressure->serialPortInit();
}

void BloodPressureDialog::on_backButton_clicked()
{
    m_bloodPressure->m_serial->serialClose();
    close();
}
